import { failure ,success} from "@/static/js/alert.js";
import instance from "../../url/community.js";

const get_index_recommend = async (type, id) => {
    if (id == undefined) { 
        id=0
    }
    // 由于处理原因首页第一份推荐不采用图片插入。不用json
    return await instance.get(`/index/index_recommend?type=${type}&id=${id}`)
        .then((response) => {
            if (response == 0) { }
            if (response == 404) {
                failure("请求失败!")
            } 
            else {
                return response
            }
        })
}

const get_user_search_history = async (userid) => { 
    return await instance.get(`/index/get/search/history?userid=${userid}`)
        .then((response) => { 
            if (response == 0) { }
            if (response == 404) {
                failure("请求失败!")
            } else {
                return response
            }
        });
}
const get_index_search_guess = async (userid = 0) => { 
    return await instance.get(`/index/get/search/guess?userid=${userid}`)
    .then((response) => { 
            if (response == 0) { }
            if (response == 404) {
                failure("请求失败!")
            } else {
                return response
            }
        });
}

const get_index_recommend_span = async () => {
    return await instance.get(`/index/recommend_span`)
}

const search_article = async (keywords, userid = 0) => {
    return await instance.get(`/index/search/article?keywords=${keywords}&userid=${userid}`)
}


export { 
    get_index_recommend,
    search_article,
    get_user_search_history,
    get_index_recommend_span,
    get_index_search_guess
}